cmake_minimum_required(VERSION 2.6)

project(relaxian C)

if (WIN32)
    set(TARGET_OPTIONS WIN32)
endif (WIN32)

find_package(SDL REQUIRED)
find_package(SDL_image REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)

include_directories(${SDL_INCLUDE_DIR}
                    ${SDLIMAGE_INCLUDE_DIR}
                    ${GLIB_INCLUDE_DIRS})

add_definitions(-DINSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\")

set(RELAXIAN_SOURCE src/battle_scene.c
                    src/controller.c
                    src/counter.c
                    src/game.c
                    src/image_pool.c
                    src/main.c
                    src/missile.c
                    src/scene.c
                    src/ship.c
                    src/sky.c
                    src/soldier.c
                    src/sprite.c)

set(LOG_ENABLED OFF CACHE BOOL "")

if (LOG_ENABLED)
    add_definitions(-DLOG_ENABLED)
    set(RELAXIAN_SOURCE ${RELAXIAN_SOURCE} src/log.c)
endif (LOG_ENABLED)

include_directories(.)
add_executable(relaxian ${TARGET_OPTIONS} ${RELAXIAN_SOURCE})
        
if (CMAKE_COMPILER_IS_GNUCC)
    set_target_properties(relaxian PROPERTIES COMPILE_FLAGS "-Wextra -Werror -std=c99 -pedantic-errors")
endif (CMAKE_COMPILER_IS_GNUCC)

target_link_libraries(relaxian ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${GLIB_LIBRARIES})

if (WIN32)
    target_link_libraries(relaxian ${SDLMAIN_LIBRARY})
endif(WIN32)

FILE(GLOB IMAGES data/*.png)
install(TARGETS relaxian RUNTIME DESTINATION bin)
install(FILES ${IMAGES} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/relaxian")
